var jwt = require('jsonwebtoken')
var key = 'fasdfsdafasdfdsfgbhdfhrtgfhtryuiktjgioerajfgtioerjtgioerajgt'

function generatorToken(e) {
    jwt.sign(e, key, {
        expiresIn: 0
    })

}
// 判断有没有登录账号的中间件
function verifyToken(req, res, next) {
    var { token } = req.cookies
    if (token) {
        jwt.verify(token, key, (result, err) => {
            if (result) {
                next()
            } else {
                res.redirect('/loginPage')
            }
        })
    } else {
        res.redirect('/loginPage')
    }
}

module.exports = {
    generatorToken,
    verifyToken
}